/* eslint-disable eqeqeq *///忽略==的警告
import { meshLog, SPRemove, SPGet, SPSet } from "../config";

function getNameInfo(pid, addr) {
    let name = '';
    let lightID = getLightId(pid, addr);
    if (pid === '1001') { name = 'A19 TW SS NS ' }
    else if (pid === '1002') { name = 'BR30 TW SS NS ' }
    else if (pid === '1003') { name = 'RDL 6" TW SS NS ' }
    else if (pid === '1004') { name = 'CDL 6" TW SS NS ' }
    else if (pid === '1005') {
        if (lightID == 2001) {
            name = 'HID 54W PT SS '
        } else if (lightID == 2002) {
            name = 'HID 115W HB SS '
        } else if (lightID == 2003) {
            name = 'HID 135W HB SS '
        } else if (lightID == 2004) {
            name = 'Garage Lighter '
        } else {
            name = 'Controller 5-Pin '
        }
    }
    else if (pid === '1006') {
        if (lightID == 2001) {
            name = 'HID MVS 54W PT SS '
        } else if (lightID == 2002) {
            name = 'HID MVS 115W HB SS '
        } else if (lightID == 2003) {
            name = 'HID MVS 135W HB SS '
        } else if (lightID == 2004) {
            name = 'Garage Lighter MVS '
        } else {
            name = 'MVS Controller 5-Pin '
        }
    }
    else if (pid === '1007') {
        if (lightID == 2001) {
            name = 'HID PIR 54W PT SS '
        } else if (lightID == 2002) {
            name = 'HID PIR 115W HB SS '
        } else if (lightID == 2003) {
            name = 'HID PIR 135W HB SS '
        } else if (lightID == 2004) {
            name = 'Garage Lighter PIR '
        } else {
            name = 'PIR Controller 5-Pin '
        }
    }
    else if (pid === '1009') { name = 'T8 Type A TW SS ' }
    else if (pid === '100A') { name = 'T8 Type B TW SS ' }
    else if (pid === '100B') { name = 'T8 Type C Driver 2L/4L ' }
    else if (pid === '100C') { name = 'Remote Control ' }
    else if (pid === '100D') { name = 'Dimmer Bridge ' }
    else if (pid === '100E') { name = 'Nano ' }
    else if (pid === '100F') { name = 'Controller Indoor Sensor ' }
    else if (pid === '1010') { name = 'A19 Filament TW SS ' }
    else if (pid === '1011') { name = 'G25 Filament TW SS ' }
    else if (pid === '1012') { name = 'B11 Filament TW SS ' }
    else if (pid === '1013') { name = 'ST19 Filament TW SS ' }
    else if (pid === '1014') { name = 'ST19 RDL 4" TW SS NS ' }
    else if (pid === '1015') { name = 'Wafer 4" TW SS NS ' }
    else if (pid === '1016') { name = 'Wafer 6" TW SS NS ' }
    else if (pid === '1017') { name = 'UVC Germicide Lamp ' }
    else if (pid === '1018') { name = 'RDL 4" TW SS NS ' }
    else if (pid === '101B') { name = 'Wireless Occupancy Sensor ' }
    else if (pid === '101C') { name = 'Controller SS Indoor Sensor ' }
    else if (pid === '101D') { name = 'T8 MVS Type B TW SS ' }
    else if (pid === '101E') { name = 'T8 Type B TW SS ' }
    else if (pid === '101F') { name = 'T8 Type B Glass Dim ' }
    else if (pid === '1020') { name = 'UVC Remote Control ' }
    else if (pid === '1021') { name = 'Dimmer PH 3-button ' }
    else if (pid === '1022') { name = 'Dimmer PH 3-button UNV ' }
    else if (pid === '1023') { name = 'Dimmer 0-10V 3-button ' }
    else if (pid === '1024') { name = 'Dimmer PH Paddle ' }
    else if (pid === '1025') { name = 'Dimmer PH Paddle UNV ' }
    else if (pid === '1026') { name = 'Dimmer 0-10V Paddle  ' }
    else if (pid === '1027') { name = 'Wafer 4" RGB SS ' }
    else if (pid === '1028') { name = 'Wafer 6" RGB SS ' }
    else if (pid === '1030') { name = 'Surface Mount 19 ' }
    else if (pid === '1032') { name = 'A19 TW SS ' }
    else if (pid === '1033') { name = 'A19 RGB SS ' }
    else if (pid === '1034') { name = 'BR30 TW SS ' }
    else if (pid === '1035') { name = 'BR30 RGB SS ' }
    else if (pid === '1037') { name = 'DISK 6" RGB SS ' }
    else if (pid === '1038') { name = 'RDL 6" RGB SS ' }
    else if (pid === '1039') { name = 'RDL 4" RGB SS ' }
    else if (pid === '103A') { name = 'Wafer 4" RGB SS UNV  ' }
    else if (pid === '103B') { name = 'Wafer 6" RGB SS UNV ' }
    else if (pid === '103C') { name = 'PIR Sensor Wire ' }
    else if (pid === '103D') { name = 'DISK 4" Disk RGB SS ' }
    else if (pid === '103E') { name = 'PIR40/LCB ' }
    else if (pid === '1040') { name = 'DC Controller Sensor ' }
    else if (pid === '1044') { name = 'MVS Sensor Wire ' }
    else if (pid === '1045') { name = 'MVS50/LCB ' }
    else if (pid === '1046') { name = 'MVS50/LCB ' }
    else if (pid === '1047') { name = 'Controller Outdoor ' }
    else if (pid === '1048') { name = 'Controller Indoor White ' }
    else if (pid === '1AOC') { name = 'USB Dongle ' }

    // meshLog("wjk name:",name);
    return name;
}


function getLightId(pid, addr) {
    // meshLog("wjk getLightId",pid,addr);
    if (pid === '1005' || pid === '1006' || pid === '1007') {
        let deviceSetx = JSON.parse(SPGet("deviceSetx"));
        // meshLog("wjk deviceSetx",deviceSetx);
        for (let i = 0; i < deviceSetx.length; i++) {
            if (deviceSetx[i].address == addr) {
                meshLog("wjk addr:", addr, " pid:", pid);
                return deviceSetx[i].lightID;
            }
        }
    }
    return 0;

}

export const getDeviceName = (addr, pid, mac) => {
    let name = getNameInfo(pid, addr);
    if (name.length >= 10) {
        name = name.substring(0, 9) + '...';
    }

    return name + mac.substring(8, mac.length);
}


export const getDeviceDetailName = (addr, pid, mac) => {
    let name = getNameInfo(pid, addr);

    return name + mac.substring(8, mac.length);
}


export const showCutName = (name) => {
    if (name.length > 12) {
        return name.substring(0, 8) + '...';
    } else {
        return name;
    }
}

export const showHeaderName = (name) => {
    if (name.length > 8) {
        return name.substring(0, 8) + '...';
    } else {
        return name;
    }
}
